@echo off
echo ===== 电影票系统环境设置 =====

REM 检查Java
echo 检查Java环境...
java -version > nul 2>&1
if %ERRORLEVEL% NEQ 0 (
    echo 未检测到Java环境。请安装Java 8或更高版本。
    echo 您可以从此处下载：https://adoptium.net/
    pause
    exit /b 1
) else (
    echo Java环境检测成功！
)

REM 创建必要的目录结构
if not exist movie_ticket_server\src\main\java\com\example\movie_ticket\model\entity (
    echo 创建后端目录结构...
    mkdir movie_ticket_server\src\main\java\com\example\movie_ticket\model\entity
    mkdir movie_ticket_server\src\main\java\com\example\movie_ticket\model\dto
    mkdir movie_ticket_server\src\main\java\com\example\movie_ticket\controller
    mkdir movie_ticket_server\src\main\java\com\example\movie_ticket\service
    mkdir movie_ticket_server\src\main\java\com\example\movie_ticket\repository
    mkdir movie_ticket_server\src\main\resources
)

REM 检查前端目录结构
if not exist movie-ticket-client (
    echo 前端项目目录不存在，是否创建？(Y/N)
    set /p answer=
    if /i "%answer%"=="Y" (
        echo 创建前端目录结构...
        mkdir movie-ticket-client
        mkdir movie-ticket-client\src
        mkdir movie-ticket-client\src\pages
        mkdir movie-ticket-client\src\components
        mkdir movie-ticket-client\src\styles
        
        REM 创建基本的package.json
        echo {> movie-ticket-client\package.json
        echo   "name": "movie-ticket-client",>> movie-ticket-client\package.json
        echo   "version": "0.1.0",>> movie-ticket-client\package.json
        echo   "private": true,>> movie-ticket-client\package.json
        echo   "dependencies": {>> movie-ticket-client\package.json
        echo     "react": "^18.2.0",>> movie-ticket-client\package.json
        echo     "react-dom": "^18.2.0",>> movie-ticket-client\package.json
        echo     "react-router-dom": "^6.8.0",>> movie-ticket-client\package.json
        echo     "antd": "^5.2.0",>> movie-ticket-client\package.json
        echo     "axios": "^1.3.2">> movie-ticket-client\package.json
        echo   },>> movie-ticket-client\package.json
        echo   "scripts": {>> movie-ticket-client\package.json
        echo     "dev": "react-scripts start",>> movie-ticket-client\package.json
        echo     "build": "react-scripts build",>> movie-ticket-client\package.json
        echo     "test": "react-scripts test",>> movie-ticket-client\package.json
        echo     "eject": "react-scripts eject">> movie-ticket-client\package.json
        echo   },>> movie-ticket-client\package.json
        echo   "browserslist": {>> movie-ticket-client\package.json
        echo     "production": [>> movie-ticket-client\package.json
        echo       ">0.2%%",>> movie-ticket-client\package.json
        echo       "not dead",>> movie-ticket-client\package.json
        echo       "not op_mini all">> movie-ticket-client\package.json
        echo     ],>> movie-ticket-client\package.json
        echo     "development": [>> movie-ticket-client\package.json
        echo       "last 1 chrome version",>> movie-ticket-client\package.json
        echo       "last 1 firefox version",>> movie-ticket-client\package.json
        echo       "last 1 safari version">> movie-ticket-client\package.json
        echo     ]>> movie-ticket-client\package.json
        echo   }>> movie-ticket-client\package.json
        echo }>> movie-ticket-client\package.json
    )
)

REM 安装Maven
if not exist tools\apache-maven-3.9.6 (
    echo 未检测到Maven，正在安装...
    call install_maven.bat
) else (
    echo Maven已安装！
)

echo ===== 环境设置完成 =====
echo 您现在可以：
echo 1. 运行mvn_build.bat构建后端项目
echo 2. 运行run_spring_boot.bat启动后端服务
echo 3. 对于前端，进入movie-ticket-client目录并运行npm install和npm run dev
echo.
echo 祝您开发顺利！

pause 